/* parser <file.xml>  */
/* compilation: gcc -std=c99 parser.c -o parser -I /usr/include/libxml2 -lxml2 */

#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <strings.h>
#include <libxml/tree.h>
#include <libxml/valid.h>
#include <libxml/xpath.h>


static void parse(xmlNodePtr current_node)
{
  /* parse current attributes */
  char* tag = (char*)current_node->name;

  /* text tag */
  if(strcasecmp(tag, "text") == 0) { /* skip */ }
  /* comment tag */
  else if(strcasecmp(tag, "comment") == 0) { /* skip */ }
  /* standard tag */
  else {
    fprintf(stderr, "+ %s\n", tag);    
    // char* property = (char*)xmlGetProp(current_node ,(xmlChar*)"myproperty");
    // xmlFree(property);    
  }
    
  /* parse children */
  xmlNodePtr child_node = current_node->children; 
  while(child_node != NULL) {  
    parse(child_node);
    child_node = child_node->next;    
  }

  /* end of parsing */  
}


int main(int argc, char* argv[])
{
  assert(argc == 2);

  /* Load XML & DTD Document */
  xmlDocPtr xmldoc = xmlParseFile(argv[1]);
  assert(xmldoc != NULL);  
  
  /* parsing */
  xmlNodePtr child_node = xmldoc->children;
  while(child_node != NULL) {  
    parse(child_node);
    child_node = child_node->next;    
  }
}
